package design.patterns.builder;

/**
 * @author daxue0929
 * @date 2023/4/17
 */

public class Client2 {

    public static void main(String[] args) {

        Phone phone = new Phone.Builder()
            .cpu("intel")
            .scree("三星屏幕")
            .memory("金士顿内存条")
            .mainBoard("华硕主板")
            .build();
        System.out.println(phone.toString());
    }
}


class Phone{
    private String cpu;
    private String screen;
    private String memory;
    private String mainBoard;

    public Phone(Builder builder) {
        this.cpu = builder.cpu;
        this.screen = builder.screen;
        this.memory = builder.memory;
        this.mainBoard = builder.mainBoard;
    }

    @Override
    public String toString() {
        return "Phone{" +
            "cpu='" + cpu + '\'' +
            ", screen='" + screen + '\'' +
            ", memory='" + memory + '\'' +
            ", mainBoard='" + mainBoard + '\'' +
            '}';
    }

    public static class Builder{
        private String cpu;
        private String screen;
        private String memory;
        private String mainBoard;

        //使用构建者创建Phone对象
        public Phone build(){
            return new Phone(this);
        }

        public Builder cpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder scree(String screen) {
            this.screen = screen;
            return this;
        }

        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }

        public Builder mainBoard(String mainBoard) {
            this.mainBoard = mainBoard;
            return this;
        }
    }
}
